package lk.icta.core.dao.impl;

import lk.icta.common.dao.impl.BaseDAO;
import lk.icta.core.dao.RegisteredPostDAO;
import lk.icta.core.entity.RegisteredPost;
import lk.icta.user.entity.User;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @author Kusal Samarakoon
 */

public class RegisteredPostDAOImpl extends BaseDAO implements RegisteredPostDAO {

    @Transactional(propagation = Propagation.MANDATORY)
    public void addRegisteredPost(RegisteredPost registeredPost, User user) {
        logger.debug("Adding a RegisteredPost {}", registeredPost.getId());
        registeredPost.getLifeCycleInfo().setCreatedTimeStamp(new Date());
        registeredPost.getLifeCycleInfo().setCreatedUser(user);
        registeredPost.getLifeCycleInfo().setLastUpdatedTimeStamp(new Date());
        registeredPost.getLifeCycleInfo().setLastUpdatedUser(user);
        em.persist(registeredPost);
    }
}
